package vip.xiaonuo.biz.modular.lancerGoods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.lancerGoods.service.BizGoodsService;
import vip.xiaonuo.biz.modular.pojo.domain.BizGoods;
import vip.xiaonuo.biz.modular.pojo.dto.add.GoodsAddDTO;
import vip.xiaonuo.biz.modular.pojo.dto.common.CommonDeleteDTO;
import vip.xiaonuo.biz.modular.pojo.dto.common.CommonDetailDTO;
import vip.xiaonuo.biz.modular.pojo.dto.edit.AttributeEdit;
import vip.xiaonuo.biz.modular.pojo.dto.edit.GoodsEditDTO;
import vip.xiaonuo.biz.modular.pojo.dto.edit.GoodsEditStatusDTO;
import vip.xiaonuo.biz.modular.pojo.dto.page.GoodsPageDTO;
import vip.xiaonuo.biz.modular.pojo.vo.KV;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Api(tags = "客户端商品")
@ApiSupport(author = "LANCER_TEAM", order = 1)
@Validated
@RestController("userBusGoodsController")
@RequestMapping
public class BusGoodsController {
    @Autowired
    private BizGoodsService GoodsService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("B端商品分页")
    @GetMapping("/biz/business/goods/page")
    @SaCheckPermission("/biz/business/goods/page")
    public CommonResult<Page<BizGoods>> page(@Valid GoodsPageDTO dto) {
        Page<BizGoods> res = GoodsService.pageBus(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("B端商品详情查询")
    @GetMapping("/biz/business/goods/detail")
    @SaCheckPermission("/biz/business/goods/detail")
    public CommonResult<BizGoods> detail(@Valid CommonDetailDTO dto) {
        BizGoods res = GoodsService.detail(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("B端商品新增")
    @PostMapping("/biz/business/goods/add")
    @SaCheckPermission("/biz/business/goods/add")
    public CommonResult<String> add(@Valid GoodsAddDTO dto) {
        GoodsService.add(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("B端商品删除")
    @PostMapping("/biz/business/goods/delete")
    @SaCheckPermission("/biz/business/goods/delete")

    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "删除id不能为空") List<CommonDeleteDTO> dto) {
        GoodsService.delete(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("B端商品编辑")
    @PostMapping("/biz/business/goods/edit")
    @SaCheckPermission("/biz/business/goods/edit")

    public CommonResult<String> edit(@Valid GoodsEditDTO dto) {
        GoodsService.edit(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("B端商品状态变更")
    @PostMapping("/biz/business/goods/edit/status")
    @SaCheckPermission("/biz/business/goods/edit/status")

    public CommonResult<String> editStatus(@RequestBody @Valid GoodsEditStatusDTO dto) {
        GoodsService.editStatus(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("B端获取商品属性的介绍")
    @GetMapping("/biz/business/goods/getINTRODUCTIONAttr")
    @SaCheckPermission("/biz/business/goods/getINTRODUCTIONAttr")
    public CommonResult<List<KV>> getINTRODUCTIONAttr(@Valid CommonDetailDTO dto) {
        List<KV> res = GoodsService.INTRODUCTIONAttr(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("B端获取商品属性的规格")
    @GetMapping("/biz/business/goods/getSTANDARDSAttr")
    @SaCheckPermission("/biz/business/goods/getSTANDARDSAttr")
    public CommonResult<List<KV>> getSTANDARDSAttr(@Valid CommonDetailDTO dto) {
        List<KV> res = GoodsService.STANDARDSAttr(dto);
        return CommonResult.data(res);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("B端更新商品属性的介绍")
    @PostMapping("/biz/business/goods/UpdateINTRODUCTIONAttr")
    @SaCheckPermission("/biz/business/goods/UpdateINTRODUCTIONAttr")
    public CommonResult<String> UpdateINTRODUCTIONAttr(@Valid @RequestBody AttributeEdit dto) {
        GoodsService.UpdateINTRODUCTIONAttr(dto);
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("B端更新商品属性的规格")
    @PostMapping("/biz/business/goods/UpdateSTANDARDSAttr")
    @SaCheckPermission("/biz/business/goods/UpdateSTANDARDSAttr")

    public CommonResult<String> UpdateSTANDARDSAttr(@Valid @RequestBody AttributeEdit dto) {
        GoodsService.UpdateSTANDARDSAttr(dto);
        return CommonResult.ok();
    }

}